﻿// <copyright file="AnalyticsCategoryLayout.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-06-05</date>
// <summary>The AnalyticsCategoryLayout class definition</summary>

namespace Microsoft.WebAnalytics.Design.Editors
{
    using System.Globalization;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for AnalyticsCategoryLayout.xaml
    /// </summary>
    public partial class AnalyticsCategoryLayout : UserControl
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the AnalyticsCategoryLayout class.
        /// </summary>
        public AnalyticsCategoryLayout()
        {
            InitializeComponent();
        }
        #endregion

        #region Implementation

        /// <summary>
        /// Opens the Silverlight Analytics Framework.chm help file
        /// </summary>
        /// <param name="sender">the button</param>
        /// <param name="e">the routed event arguments</param>
        private void OpenHelp(object sender, RoutedEventArgs e)
        {
            var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Silverlight Analytics Framework", false);

            if (key == null)
            {
                System.Windows.MessageBox.Show(
                    Properties.Resources.InstallationError, 
                    Properties.Resources.SilverlightAnalyticsFramework, 
                    MessageBoxButton.OK, 
                    MessageBoxImage.Error);
            }
            
            var installDir = key.GetValue("InstallDir") as string;

            key.Close();

            var helpPath = installDir + @"Help\Microsoft Silverlight Analytics Framework.chm";

            if (!System.IO.File.Exists(helpPath))
            {
                var message = string.Format(CultureInfo.CurrentCulture, Properties.Resources.HelpFileDoesNotExist, helpPath);

                System.Windows.MessageBox.Show(message, Properties.Resources.SilverlightAnalyticsFramework, MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            System.Diagnostics.Process.Start(helpPath);
        }
        #endregion
    }
}
